<div id="formDiv" style="height: 100%"></div>

<script type="text/html" id="formContent">
  <form lay-filter="exchangeRecordsForm" class="layui-form open-form" id="exchangeRecordsForm">
      <div class="open-model">
          <div class="open-auto">
              <input name="id" type="hidden"/>
              <div class="layui-form-item">
                  <div class="layui-col-md4">
                      <label class="layui-form-label">{{d.typeNameData}}类型</label>
                        <div class="layui-input-block">
                                            <select id="type" name="type" lay-filter="type">
                                            </select>
                      </div>
                              </div>
                  <div class="layui-col-md4">
                      <label class="layui-form-label">供应商名称</label>
                      <div class="layui-input-block">
                                         <select id="supplierId" name="supplierId" lay-filter="supplierId">
                          </select>
                      </div>
                  </div>

                  <div class="layui-col-md4">
                      <label class="layui-form-label">运单编号</label>
                      <div class="layui-input-block">
                          <select id="waybillNo" name="waybillNo" lay-filter="waybillNo">
                          </select>
                      </div>
                  </div>
              </div>
              <div class="layui-form-item">
                  <div class="layui-col-md4">
                      <label class="layui-form-label">关联订单编号</label>
                      <div class="layui-input-block">
                          <input id="purOrderCode" class="layui-input adv-disable" type="text" name="purOrderCode" disabled/>
                          <input id="purOrderId" class="layui-input" type="hidden" name="purOrderId"/>
                          </select>
                      </div>
                  </div>

                  <div class="layui-col-md4">
                      <label class="layui-form-label">{{d.typeNameData}}备注</label>
                      <div class="layui-input-block">
                          <input name="remark" id="remark" class="layui-input" type="text"/>
                      </div>
                  </div>

              </div>
              <table class="layui-table" lay-filter="formTableHis" id="formTableHis"></table>
          </div>
          <div class="layui-form-item text-right">
              <div class="right-btn">
                  <button class="layui-btn layui-btn-primary " type="button" ew-event="closeDialog">关闭
                  </button>
                  <button class="layui-btn" lay-filter="productDetailSubmit" lay-submit>提交</button>
              </div>
          </div>
      </div>
  </form>
</script>

<script>
  layui.use(['layer', 'form', 'table', 'admin', 'laytpl'], async function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    var laytpl = layui.laytpl;

    const nowData = { ...parentData };
    data = parentData.data ? { ...parentData.data } : '';
    form.render('select');
    laytpl(formContent.innerHTML).render({ ...nowData }, function (html) {
      $('#formDiv').html(html);
    });
    admin.setFormDisable('#exchangeRecordsForm', true);

    await admin.initDataSelectPro(nowData.selectTypeSrc, {}, 'type', `${nowData.typeNameData}类型`);
    await admin.initDataSelectPro('enterprise/purchase/admin/supplierInfoPass/list', {}, 'supplierId', `供应商名称`, null, 'corporateName');
    const returnTypeList = await admin.getDictListPro('returnType', 'return_method', `发货方式`);
    table.render({
      elem: '#formTableHis',
      data: [],
      page: false,
      cols: [
        [
          { type: 'numbers', title: '序号', fixed: 'left' },
          {
            field: 'returnType',
            title: '发货方式',
            templet: admin.setTableSelect(
              'returnType',
              returnTypeList.map((v) => ({ value: v.labelValue, label: v.labelName })),
              true,
            ),
          },
          { field: 'logisticsCompany', title: '物流公司' },
          { field: 'waybillNo', title: '退货运单号' },
          { field: 'busNumber', title: '车牌号' },
          {
            field: 'remark',
            title: '备注',
            templet: admin.setTableInput('remark', true),
          },
          {
            title: '操作',
            templet: function () {
              return `<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="detail">详情</a>`;
            },
          },
        ],
      ],
      done: function (data) {
        admin.tableInputChange('formTableHis');
      },
    });
    if (data.supplierId) {
      await admin.initDataSelectPro('enterprise/purchase/admin/purchaseDeliveryRecord/getWaybillInfoBy', { supplierId: data.supplierId }, 'waybillNo', '运单编号', (d, obj) => {}, 'waybillNo');
    }
    if (data.id) {
      table.reload('formTableHis', { data: data.sendSelGoodsLogisticsDetails });
      form.val('exchangeRecordsForm', data);
    } else {
    }

    table.on('tool(formTableHis)', function (obj) {
      const { event, data } = obj;
      console.log(data);
      let dataList=data.selGoodsLogisticsDetails
      admin.formOpen({
        title: `查看${nowData.typeNameData}记录详情`,
        area: ['70%', '40%'],
        content: '<table id="returnRecordsFormTable" lay-filter="returnRecordsFormTable"></table>',
        success: function () {
          table.render({
            elem: '#returnRecordsFormTable',
            data: dataList,
            cols: [
              [
                {
                  field: 'skuCode',
                  title: '产品编号',
                },
                {
                  field: 'skuSpec',
                  title: '规格码',
                },
                {
                  field: 'skuName',
                  title: '产品名称',
                },
                {
                  field: 'mainUnitName',
                  title: '主计价单位',
                },
                {
                  title: '收货数量',
                  templet: function (d) {
                    return d.realGetQuantity ? d.realGetQuantity : d.realSendQuantity;
                  },
                },
                {
                  field: 'unitPrice',
                  title: '单价',
                },
                {
                  field: 'totalPrice',
                  title: '总价',
                },
              ],
            ],
          });
        },
      });
   
 
    });
  });
</script>

<style>
  #exchangeRecordsForm .layui-form-label {
    width: 100px;
  }

  #exchangeRecordsForm .layui-input-block {
    margin-left: 130px;
  }

  #exchangeRecordsForm .layui-input-inline {
    margin-bottom: 15px;
  }
</style>
